翻訳と辞書
Words near each other
・ Respectability politics
・ Respectable
・ Respectable (Mel and Kim song)
・ Respectable (The Rolling Stones song)
・ Respectable (TV series)
・ Respectable Groove
・ Resource (computing)
・ Resource (disambiguation)
・ Resource (Java)
・ Resource (project management)
・ Resource (Windows)
・ Resource Academia
・ Resource academia
・ Resource Access Control Facility
・ Resource acquisition ability
Resource Acquisition Is Initialization
・ Resource allocation
・ Resource allocation (computer)
・ Resource Allocation Working Party
・ Resource and Energy Economics
・ Resource Area for Teaching
・ Resource base of Communist Czechoslovakia
・ Resource Based Economy
・ Resource bounded measure
・ Resource breakdown structure
・ Resource Central
・ Resource consent
・ Resource Conservation and Development Program
・ Resource Conservation and Recovery Act
・ Resource construction set


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Resource Acquisition Is Initialization : ウィキペディア英語版
Resource Acquisition Is Initialization

Resource Acquisition Is Initialization (RAII)〔Bjarne Stroustrup (Why doesn't C++ provide a "finally" construct? ) Accessed on 2013-01-02.〕 is a programming idiom used in several object-oriented languages, most prominently C++, where it originated, but also D, Ada, Vala, and Rust. The technique was developed for exception-safe resource management in C++ during 1984–89, primarily by Bjarne Stroustrup and Andrew Koenig, and the term itself was coined by Stroustrup. RAII is generally pronounced as an initialism, sometimes pronounced as "R, A, double I".〔"(How do you pronounce RAII? )", ''StackOverflow''〕
In RAII, holding a resource is tied to object lifetime: resource allocation (acquisition) is done during object creation (specifically initialization), by the constructor, while resource deallocation (release) is done during object destruction, by the destructor. If objects are destroyed properly, resource leaks do not occur.
Other names for this idiom include ''Constructor Acquires, Destructor Releases'' (CADRe) 〔https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/UnarLCzNPcI〕 and one particular style of use is called ''Scope-based Resource Management'' (SBRM).〔http://books.google.com/books?id=bIxWAgAAQBAJ&pg=PA4&lpg=PA4&dq=%22scope+based+resource+management%22&source=bl&ots=2MjJtUW991&sig=VKrsj2_c_Ao3FQ7TsnK47DILQE0&hl=en&sa=X&ei=llhNU4SPLO6GyQG84oGwCQ&ved=0CG8Q6AEwBw#v=onepage&q=%22scope%20based%20resource%20management%22&f=false〕 This latter term is for the special case of automatic variables. RAII ties resources to object ''lifetime,'' which may not coincide with entry and exit of a scope (notably variables allocated on the free store have lifetimes unrelated to any given scope). However, using RAII for automatic variables (SBRM) is the most common use case.
==C++11 example==
The following C++11 example demonstrates usage of RAII for file access and mutex locking:

#include
#include
#include
#include
#include
void write_to_file (const std::string & message)

This code is exception-safe because C++ guarantees that all stack objects are destroyed at the end of the enclosing scope, known as stack unwinding. The destructors of both the ''lock'' and ''file'' objects are therefore guaranteed to be called when returning from the function, whether an exception has been thrown or not.〔(【引用サイトリンク】url=http://www.parashift.com/c++-faq/dtors-shouldnt-throw.html )
Local variables allow easy management of multiple resources within a single function: they are destroyed in the reverse order of their construction, and an object is destroyed only if fully constructed—that is, if no exception propagates from its constructor.〔(【引用サイトリンク】url=http://www.parashift.com/c++-faq/order-dtors-for-locals.html )
Using RAII greatly simplifies resource management, reduces overall code size and helps ensure program correctness. RAII is therefore highly recommended in C++, and most of the C++ standard library follows the idiom.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Resource Acquisition Is Initialization」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.